package dome1;

import java.lang.reflect.Array;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-06-22
 * Time: 20:18
 */
class MyArray3<T> {
    //通过反射创建数组不常用!!!
    public T[] obj;
    public MyArray3(Class<T> clazz,int capacity) {
        //通过反射创建
        obj = (T[]) Array.newInstance(clazz,capacity);
    }
    public T getPos(int pos) {
        return obj[pos];
    }
    public void setObj(int pos,T val) {
        obj[pos] = val;
    }
}
public class Test3 {
    public static void main(String[] args) {
        MyArray3<Integer> myArray3 = new MyArray3<>(Integer.class,10);
        myArray3.setObj(0,10);
        myArray3.setObj(1,20);
        myArray3.setObj(2,30);

        Integer a = myArray3.getPos(0);
        System.out.println(a);
    }
}
